
function ActivityManager() {
	var activities = new Array();
	var busy = false;
	
	this.pushActivity = function(activityHTML) { 
		if (activityHTML) {
			debug("[ActivityManager.js] Received new Activity."); 
			activities.push(activityHTML);
			shiftActivity();
		} 
	};
	
	var shiftActivity = function() {
		if (activities.length > 0) {
			if (!busy) { // no activity is currently visible
				busy = true;
				debug("[ActivityManager.js] Showing Activity."); 
				var act = new Activity(activities.shift());
				act.addEventListener("activityClose", activityClose);
			}
			else { // there is an activity currently visible, try again later
				debug("[ActivityManager.js] Waiting for another Activity to finish.");  
				setTimeout(function(){
					shiftActivity();
				}, 1000);
			}
		}
	};
	
	var activityClose = function(evt) {
		debug("[ActivityManager.js] An Activity just finished.");
		busy = false; 
	};
	
}
